<template>
  <div class="page">
    <div class="flex group">
      <template v-if="AppleAssembleList.length">
      <div class="group_item" v-for="(item,index) in AppleAssembleList" :key="index">
        <a @click="goDetail(item)">
          <div class="group_pic">
            <img :src="item.pic_url" mode="widthFix">
            <div class="nownumber">{{item.memberNum?item.memberNum:0}}人团</div>
            <div class="saled"><span>已团{{item.alreadyNum}}件</span></div>
          </div>
          <div class="group_title">{{item.actv_content}}</div>
          <div class="group_tag">{{item.type_desc}}</div>
          <div class="price">
            <span class="price_now">¥{{item.grpAmount*0.01}}</span>
            <span class="price_old">¥{{item.item_price*0.01}}</span>
          </div>
        </a>
      </div>
      </template>
        <div style="text-align:center;margin-top:0.9em;" v-if="!AppleAssembleList.length">
          暂无数据
        </div>
    </div>
  </div>
</template>

<script>
import card from '@/components/card'
  import * as appId from "@/utils/util"
export default {
  data () {
    return {
       AppleAssembleList:[],
      pageNo:1,
      pageSize:10,
      result:[]
    }
  },

  components: {
    card
  },
   onPullDownRefresh(){
     console.log('down')
      if(this.result.length){
     this.pageNo++;
    }
     this.getAppleAssembleListFun()

  },
  onReachBottom () {
    wx.showNavigationBarLoading()
    console.log('pull')
    if(this.result.length){
     this.pageNo++;
    }
    this.getAppleAssembleListFun()
    // wx.stopPullDownRefresh()
   },
   onShow(){
     wx.setNavigationBarTitle({
       title: "拼团列表"
     })
     this.pageNo=1;
    this.getAppleAssembleListFun()
   },
  methods: {
    goDetail(row){
      let url="/pages/groupdetail/main?id="+row.id;
      // wx.setStorageSync('AppleAssembleList', JSON.stringify(row))
      wx.navigateTo({ url })
    },
    getAppleAssembleListFun(){
      let that=this;
       this.$http.request({
            method: "post",
            url: "/v1.0/appletHome/appletAssembleList",
            body: {
              "appid": appId.appId,
              "pageNo": that.pageNo,
              "pageSize": that.pageSize,
              status:'0'
            }
          }).then((data)=>{
              if(data.code==0){
              this.result=data.result;
               if (that.pageNo > 1) {
              that.AppleAssembleList.push(...data.result)
              }else{
                that.AppleAssembleList=data.result;
                 that.AppleAssembleList.forEach((a,i)=>{
                  let arr=JSON.parse(a.range_group);
                  arr.forEach((m,n)=>{
                   m.result.forEach((x,y)=>{
                     a.memberNum=x.memberNum;
                   })
                  })
                 })
              }
               if(!data.length){
               wx.stopPullDownRefresh();
              //  wx.showToast({
              //   title: '暂无更多数据',
              //   icon: 'none',
              //   duration: 2000
              // })
            }
            }else{
                wx.showToast({
                title: `${data.message}`,
                icon: 'none',
                duration: 2000
              })
            }
          })
         // .catch((err)=>{
         //    wx.showToast({
         //        title: '获取失败',
         //        icon: 'none',
         //        duration: 2000
         //      })
         //  })
    },
    bindViewTap () {
      const url = '../logs/main'
      if (mpvuePlatform === 'wx') {
        mpvue.switchTab({ url })
      } else {
        mpvue.navigateTo({ url })
      }
    }
  },

  created () {
    // let app = getApp()
  }
}
</script>

<style scoped>
.price{
  line-height: 1.1em;
}
.price .price_now{
  color:#E4393C;
  font-size:0.8em;
}
.price .price_old{
  margin-left: 0.2em;
  color:#999;
  font-size:0.7em;
  text-decoration:line-through
}
.group{
  padding: 0 0.3em;
}
.group .group_item{
  width: 50%;
  float: left;
  margin-bottom: 0.6em;
}
.group .group_item a{
  margin: 0 0.3em;
}
.group .group_item img{
  width: 100%;
}
.group .group_item .group_pic{
  position: relative;
}
.group .group_item .group_pic .nownumber{
  position: absolute;
  top: 0.4em;
  right: 0px;
  background: #FF787E;
  width: 4em;
  height: 1.6em;
  line-height: 1.6em;
  color: #fff;
  font-size: 0.7em;
  text-align: center;
  border-radius: 0.6em 0px 0px 0.6em;
}
.group .group_item .group_pic .saled{
  position: absolute;
  bottom: 0px;
  left: 0px;
  right: 0px;
  background: #FF787E;
  height: 1.6em;
  line-height: 1.6em;
  color: #fff;
  font-size: 0.7em;
  text-align: right;
}
.group .group_item .group_pic .saled span{
  padding: 0 0.4em;
}
.group_title{
  font-size: 0.8em;
  margin-top: 0.3em;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.group_tag{
  color: #666;
  font-size: 0.7em;
}
</style>
